import * as apiService from '@/services/api';

/**
 * 获取充值记录
 * @param {number} subStatus 充值记录子类型
 * @param {number} dateType 时间类型：1充值时间，2加币时间
 * @param {date} startTime 开始时间
 * @param {date} endTime 截止时间
 * @param {number} userType 用户类型：-1全部，0玩家，1代理
 * @param {number} bankId 银行Id
 * @param {number} minAmount 最小充值金额
 * @param {number} maxAmount 最大充值金额
 * @param {number} clientType 客户端类型：-1全部，0PC，1H5，2安卓，3IOS，4PAD
 * @param {number} status 支付状态：-1全部，0待支付，1支付成功，2支付失败
 * @param {number} paymentId 支付方式ID：-1全部，-2全部第三方入款，-3全部转账入款
 * @param {number} searchType 搜索类型：1充值单号，2账号名,3姓名，4手机号，5收款商户号，6第三方充值订单号，7补单审核人
 * @param {string} keywords 搜索关键词
 * @param {string} level 用户层级（直接传名称）
 * @param {string} merchant 入款商户
 * @param {number} limitType 充值额度分类，-1:全部（默认），0：普通充值，1：大额充值
 * @param {number} page 页码
 * @param {number} size 单页记录条数
 * @return {*} Promise
 */
export function getRechargeLogs({
  subStatus,
  dateType,
  startTime,
  endTime,
  userType,
  bankId,
  minAmount,
  maxAmount,
  clientType,
  payStatus,
  paymentId,
  searchType,
  keywords,
  level,
  merchant,
  merchantCode,
  limitType,
  page = 1,
  size = 20,
  status,
} = {}) {
  return apiService.post('/gl/recharge/manage/list', {
    subStatus,
    dateType,
    startTime,
    endTime,
    userType,
    bankId,
    minAmount,
    maxAmount,
    clientType,
    payStatus,
    paymentId,
    searchType,
    keywords,
    level,
    merchant,
    merchantCode,
    limitType,
    page,
    size,
    status,
  });
}
/**
 * 获取充值补单申请列表
 * @param {date} startTime 开始时间
 * @param {date} endTime 截止时间
 * @param {string} username 账户名
 * @param {number} applicant 补单申请人
 * @param {string} auditor 补单审核人
 * @param {number} reallyName 姓名
 * @param {string} telephone 手机号
 * @param {string} thirdOrderId 第三方单号
 * @param {string} orderId 充值单号
 * @param {number} status 支付状态：-1全部，0待待审核，1审核通过，2审核拒绝
 * @param {number} limitType 额度类型，-1：全部，0：普通充值，1：大额充值
 * @param {number} userType 用户类型：-1全部，0玩家，1代理
 * @param {number} page 页码
 * @param {number} size 单页记录条数
 * @return {*} Promise
 *
 */
export function getRechargeReorders({
  startTime,
  endTime,
  username,
  applicant,
  auditor,
  reallyName,
  telephone,
  thirdOrderId,
  orderId,
  status,
  limitType,
  userType,
  page = 1,
  size = 20,
} = {}) {
  return apiService.post('/gl/recharge/manage/list/success', {
    startTime,
    endTime,
    username,
    applicant,
    auditor,
    reallyName,
    telephone,
    thirdOrderId,
    orderId,
    status,
    limitType,
    userType,
    page,
    size,
  });
}

/**
 * 查询三方状态
 * @param params
 * @returns {Promise<*>}
 *
 */
const getThirdStatus = params => apiService.post(api.THIRD_STATUS, params);

/**
 * 获取充值补单申请人列表
 * @param params
 * @returns {Promise<*>}
 *
 */
const getRechargeManageApplicant = params => apiService.post(api.FINANCE_RECHARGE_MANAGE_APPLICANT, params);
/**
 * 获取充值补单申请人列表
 * @param params
 * @returns {Promise<*>}
 *
 */
const getRechargeManageAuditor = params => apiService.post(api.FINANCE_RECHARGE_MANAGE_AUDITOR, params);
/**
 * 获取充值异常处理人列表
 * @param params
 * @returns {Promise<*>}
 *
 */
const getExceptionRechargeAuditterList = params => apiService.post(api.FINANCE_RECHARGE_EXCEPTIONS, params);
/**
 * 获取充值异常列表
 * @param params
 * @returns {Promise<*>}
 *
 */
const getRechargeExceptions = params => apiService.post(api.FINANCE_RECHARGE_EXCEPTIONS, params);

/**
 * 处理异常操作
 * @param params
 * @returns {Promise<*>}
 *
 */
const handleRechargeException = ({ comment, id }) => apiService.post(api.FINANCE_RECHARGE_EXCEPTION_HANDLE, { comment, id });
/**
 * 查询所有充值方式
 * @param params
 * @returns {Promise<*>}
 *
 */
const getPaymentManageList = params => apiService.post(api.FINANCE_PAYMENT_MANAGE_LIST, params);
/**
 * 查询所有充值渠道
 * url /gl/payment/manage/list/channel
 * @param params
 * @returns {Promise<*>}
 *
 */
const getPaymentManageChannelList = params => apiService.post(api.FINANCE_PAYMENT_MANAGE_CHANNEL_LIST, params);

/**
 * 申请补单
 * @param params
 * @returns {Promise<*>}
 *
 */
const applyReorder = params => apiService.post(api.FINANCE_APPLY_REORDER, params);
/**
 * 申请单个补单
 * @param params
 * @returns {Promise<*>}
 *
 */
const applySingleReorder = params => apiService.post(api.FINANCE_SINGLE_REORDER, params);
/**
 * 上分清算信息
 * @param params
 * @returns {Promise<*>}
 *
 */
const applyCreditClearReorder = params => apiService.post(api.FINANCE_SINGLE_CREDITCLEAR, params);
/**
 * 上分清算
 * @param params
 * @returns {Promise<*>}
 *
 */
const applyCreditClearReorderSet = params => apiService.post(api.FINANCE_SINGLE_CREDITCLEAR_SET, params);
/**
 * 拒绝补单
 * @param params
 * @returns {Promise<*>}
 *
 */
const refusedSingleReorder = params => apiService.post(api.FINANCE_SINGLE_REJECT, params);


const multiplyApplyReorder = params => apiService.post(api.MULTIPLY_FINANCE_APPLY_REORDER, params);
/**
 * 补单审核
 * @param params
 * @returns {Promise<*>}
 *
 */
const auditReorder = params => apiService.post(api.FINANCE_AUDIT_REORDER, params);

/**
 * 获取审核人列表
 * @param params
 * @returns {Promise<*>}
 *
 */
const getAuditterList = () => apiService.post(api.FINANCE_AUDITTER_LIST);
/**
 * 获取申请人列表
 * @param params
 * @returns {Promise<*>}
 *
 */

/**
 * 获取某个第三方的商户列表
 * @param params {id:'第三方商户'}
 * @return {Promise<*>}
 */
const getEscrowShopNoList = params => apiService.post(api.FINANCE_ESCROW_SHOPNO_LIST, params);

/**
 * 查询所有收款银行
 * /gl/payment/manage/list/bank
 * @param params
 * @return {Promise<*>}
 */
const getPayeeBankList = params => apiService.post(api.FINANCE_PAYEE_BANK_LIST, params);

/**
 * 获取某个银行下面的卡列表
 * @param params
 * @return {Promise<*>}
 */
const getBankCardList = params => apiService.post(api.FINANCE_BANK_CARD_LIST, params);

/**
 * 获取充值金额设置列表
 * @param {number} limitType 额度类型，0 :普通充值， 1:大额充值
 * @param {number} merchantId 三方商户ID
 * @return {*} Promise
 */
export function getRechargeLimitSettings({
  limitType,
  merchantId,
} = {}) {
  return apiService.post('/gl/payment/manage/list/fee', {
    limitType,
    merchantId,
  });
}

/**
 * 新增充值金额设置
 * @param {number} limitType 额度类型，0 :普通充值， 1:大额充值
 * @param {number} clientType 应用端(0-P C、1-移动端 )
 * @param {number} userType 用户类型(0 -会员、1-代理)
 * @param {number} merchantId 三方商户ID
 * @param {number} paymentId 支付方式ID
 * @param {number} feeId 手续费ID
 * @param {number} feeRate 手续费配置
 * @param {number} maxFee 最大手续费金额
 * @param {number} minAmount 最小充值金额
 * @param {number} maxAmount 最大充值金额
 // * @param {string} fastAmount 快捷金额
 * @return {*} Promise
 */
export function addRechargeLimitSetting({
  limitType,
  clientType,
  userType,
  merchantId,
  paymentId,
  feeId,
  feeRate,
  maxFee,
  minAmount,
  maxAmount,
  // fastAmount,
} = {}) {
  return apiService.post('/gl/payment/manage/update/fee', {
    limitType,
    clientType,
    userType,
    merchantId,
    paymentId,
    feeId,
    feeRate,
    maxFee,
    minAmount,
    maxAmount,
    // fastAmount,
  });
}

/**
 * 新增充值金额设置
 * @param {*} bankList 银行卡列表
 * {
 *   paybankId 充值银行ID
 *   status 银行状态:0 正常，1禁用
 *   minAmount 最低限额
 *   maxAmount 最高限额
 * }
 * @return {*} Promise
 */
export function addRechargeBankLimit({
  bankList,
} = {}) {
  return apiService.post('/gl/payment/manage/update/bank/limit', {
    bankList,
  });
}

/**
 * 查询充值金额设置列表
 * @param {number} channelId 渠道ID
 * @return {*} Promise
 */
export function getRechargeBankLimitList({
  channelId,
} = {}) {
  return apiService.post('/gl/payment/manage/find/bank/list', {
    channelId,
  });
}

/**
 * 设置一组值，这组值用于充值时进行快捷金额的选择的接口
 * @param {array} amounts 一组金额，例如100,200,300,400
 * @param {number} limitType 额度分类，0：普通充值(默认)，1：大额充值
 * @return {*} Promise
 */

export function updateRechargeQuickAmountForApp({
  amounts,
  limitType,
} = {}) {
  return apiService.post('/gl/payment/manage/update/fastAmount', {
    amounts,
    limitType,
  });
}


/**
 * 获取充值金额设置详情
 * @param params
 * @return {Promise<*>}
 */

const getRechargeLimitDetail = params => apiService.post(api.FINANCE_RECHARGE_LIMIT_DETAIL, params);

/**
 * 修改充值金额设置状态
 * @param params
 * @return {Promise<*>}
 */

const updateRechargeLimitStatus = params => apiService.post(api.FINANCE_RECHARGE_LIMIT_STATUS, params);


/**
 * 导出三方充值记录明细
 * @param params
 * @return {Promise<*>}
 */

const exportThirdCharge = params => apiService.post(api.EXPORT_THIRD_CHARGE_LOGS, params);

/**
 * 导出充值补单审核记录明细
 * @param params
 * @return {Promise<*>}
 */
const exportReorderAudit = params => apiService.post(api.EXPORT_REORDER_AUDIT_LOGS, params);

/**
 *
 * @param params
 * @returns {Promise<*|*|*|undefined>}
 */
const getRecordExceptionRecord = params => apiService.post(api.FINANCE_RECHARGE_EXCEPTION_RECORD, params);

const addEscrowSet = (params) => {
  const {
    id, paymentId, channelId, merchantId, clientType, remark,
  } = params;
  if (_.isUndefined(id)) {
    return apiService.post(api.FINANCE_ADD_ESCROW_SET, params);
  }
  return apiService.post(api.FINANCE_UPDATE_ESCROW_SET, {
    id,
    paymentId,
    channelId,
    merchantId,
    clientType,
    remark,
  });
};

/**
 * 获取支付宝下面的实名列表
 * @param params
 * @return {Promise<*>}
 */
const getAlipayNameList = (params) => {
  const { id } = params;
  return apiService.post(api.FINANCE_ALIPAY_NAME_LIST, params);
};

/**
 * 获取是否开始通道展示接口
 * @returns {Promise<*|*|*|undefined>}
 */
const getShowMerchantApi = () => apiService.post(api.SHOWMERCHANTGET);

/**
 * 保存是否开启通道展示接口
 * @param status
 * @returns {Promise<*|*|*|undefined>}
 */
const saveShowMerchantApi = (params) => apiService.post(api.SHOWMERCHANTSET, params);

/**
 * 获取充值补单订单详情
 * @param orderId
 * @returns {Promise<*|*|*|undefined>}
 */

const getRechargeOrderDetailApi = ({ orderId } = {}) => apiService.post(api.FINANCE_RECHARGE_ORDER_DETAIL,{
  orderId,
});

export {
  getExceptionRechargeAuditterList,
  getRechargeExceptions,
  handleRechargeException,
  applyReorder,
  multiplyApplyReorder,
  applySingleReorder,
  applyCreditClearReorder,
  applyCreditClearReorderSet,
  refusedSingleReorder,
  auditReorder,
  getAuditterList,
  getEscrowShopNoList,
  getBankCardList,
  getRechargeLimitDetail,
  updateRechargeLimitStatus,
  getRechargeManageApplicant,
  getRechargeManageAuditor,
  getPaymentManageChannelList,
  getPaymentManageList,
  getPayeeBankList,
  exportThirdCharge,
  exportReorderAudit,
  getRecordExceptionRecord,
  addEscrowSet,
  getAlipayNameList,
  getShowMerchantApi,
  saveShowMerchantApi,
  getThirdStatus,
  getRechargeOrderDetailApi,
};
